<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>TITLE</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <input type="hidden" th:value="${id} " id="id" name="id" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">群名称</label>
            <div class="layui-input-inline">
                <input type="groupName" id="groupName" name="groupName" placeholder="请输入群名称" autocomplete="off"
                       class="layui-input"  disabled="true">
            </div>

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选择标签</label>
        <div class="layui-input-inline" >
            <select id="label" name="label" lay-filter="select-fileType" >
                <option value="">请选择</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">欢迎语</label>
            <div class="layui-input-inline">
                <input type="welcome" id="welcome" name="welcome" placeholder="请输入新人进来的欢迎语" autocomplete="off"
                       class="layui-input" style="width: 500px;height: 100px">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit">确认保存</button>
        </div>
    </div>
</div>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    window.onload = function () {
        var id = $("#id").val()
        var DistData ={
            dictId: "1465870378994847745",
            limit:9999,
            page:1
        }
        CoreUtil.sendPost("/sysDictDetail/listByPage",DistData,function (res){
              if(res.code == 0){
                  var str = $("#label").html();
                  for(var i =0;i<res.data.records.length;i++){
                      str += `<option value="${res.data.records[i].id}">${res.data.records[i].label}</option>`;
                  }
                  $("#label").html(str)
                  form.render("select");
              }
        });

        if (!CoreUtil.isEmpty(id)) {
            CoreUtil.sendGet('/wechatGroup/' + id, null, function (res) {
                if (res.data != null) {
                    $("#groupName").val(res.data.groupName);
                    $("#welcome").val(res.data.welcome);
                    $("#label").val(res.data.label)
                    $("#groupName").val(res.data.groupName);
                    $("#groupName").val(res.data.groupName);
                    $("#groupName").val(res.data.groupName);
                    $("#groupName").val(res.data.groupName);
                }
            })
        }
    }
    //监听提交
    form.on('submit(submit)', function (data) {
        CoreUtil.sendPut("/wechatGroup/update", data.field, function (res) {
            if (res.code == 0) {
                //跳出提示
                parent.layer.msg(res.msg);
                //刷新表格
                setTimeout(function () {
                    parent.location.reload();
                }, 1000)
            } else {
                layer.msg(res.msg);
            }
        });
        return false;
    });
</script>
</body>
</html>